package com.sdry.web.controller.cb;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sdry.model.cb.AmoebaEntity;
import com.sdry.model.cb.HydroPower;
import com.sdry.model.cb.ShareEntity;
import com.sdry.model.cb.TableDataInfo;
import com.sdry.service.cb.AmoebaService;
import com.sdry.service.cb.HydroPowerService;
import com.sdry.utils.BigDecimalUtil;
import com.sdry.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;


/**
 * 阿米巴结算
 * @author cb
 * 2019年9月28日14:11:54
 */
@Controller
@RequestMapping("amoeba")
public class AmoebaController extends BaseController {


    @Autowired
    private AmoebaService amoebaService;

    @RequestMapping()
    public String index(Model model) {
        //A 上面的外部
        String date = "2019-09-28";
        List<AmoebaEntity> amoebaEntities = amoebaService.listPartA(date);
        BigDecimal t1 = new BigDecimal("0");
        for (AmoebaEntity ae : amoebaEntities) {
            if (ae.getMonery() == null){
                ae.setMonery(new BigDecimal("0"));
            }
            BigDecimal t2 = ae.getMonery();
            String t3 = BigDecimalUtil.add(t1.toString(), t2.toString());
            t1 = new BigDecimal(t3);
        }


        //叉车折旧
        BigDecimal chaCheZheJiu = amoebaService.chaCheZheJiu("2019-09-28");
        //叉车租赁
        BigDecimal cheZuLin = amoebaService.cheCheZuLin("2019-09-28");
        //其他
        BigDecimal qiTa = amoebaService.qiTa("2019-09-28");

        //查询底薪总和
        BigDecimal gongZi = amoebaService.gongZi("2019-09-28");
        //查询月过桥费总和
        BigDecimal guoQiaoFei = amoebaService.guoQiaoFei("2019-09-28");
        //-查询月油费总和
        BigDecimal youFei = amoebaService.youFei("2019-09-28");
        //查询月维修费总和
        BigDecimal weiXiuFei = amoebaService.weiXiuFei("2019-09-28");
        //查询月外雇车总和
        BigDecimal waiGuChe = amoebaService.waiGuChe("2019-09-28");
        //查询月服务费总和
        BigDecimal fuWuFei = amoebaService.fuWuFei("2019-09-28");
        //查询月社保费总和
        BigDecimal sheBaoFei = amoebaService.sheBaoFei("2019-09-28");
        //待摊
        BigDecimal daiTan = amoebaService.daiTanFei("2019-09-28",14L);

        BigDecimal zheJiuFie = amoebaService.zheJiuFie("2019-09-28");
        model.addAttribute("chaCheZheJiu",chaCheZheJiu);
        model.addAttribute("cheZuLin",cheZuLin);
        model.addAttribute("qiTa",qiTa);
        model.addAttribute("zheJiuFie",zheJiuFie);

        model.addAttribute("gongZi",gongZi);
        model.addAttribute("guoQiaoFei",guoQiaoFei);
        model.addAttribute("youFei",youFei);
        model.addAttribute("weiXiuFei",weiXiuFei);
        model.addAttribute("waiGuChe",waiGuChe);
        model.addAttribute("fuWuFei",fuWuFei);
        model.addAttribute("sheBaoFei",sheBaoFei);
        model.addAttribute("daiTan",daiTan);
        model.addAttribute("shouRuMoney",t1);

        return "/cb/amoeba";
    }

    @RequestMapping("listPartA")
    @ResponseBody
    public TableDataInfo listPartA() {
        String date = "2019-09-28";
        List<AmoebaEntity> amoebaEntities = amoebaService.listPartA(date);
       return getDataTable(amoebaEntities,100);
    }

    @RequestMapping("page")
    public String sharePage() {

        return "cb/share";
    }

    @RequestMapping("getShareList")
    @ResponseBody
    public TableDataInfo getShareList(
            @RequestParam("page") Integer page ,
            @RequestParam("pageSize") Integer pageSize
    ) {
        PageHelper.startPage(page,pageSize);
        List<ShareEntity> list = amoebaService.getShareList("2019-09-28",14L);
        PageInfo pageInfo = new PageInfo(list,5);
        return getDataTable(pageInfo.getList(),Math.toIntExact(pageInfo.getTotal()));
    }


}
